package shun.vm.instructions;

import shun.vm.VM;

/**
 * Created by chen on 14-5-18.
 */
public class mul extends Instruction {

    private int mOprand1;
    private int mOprand2;

    public mul(VM vm) {
        super(vm);
    }

    @Override
    public void parse(byte[] codes, int start) {
        byte opcode = codes[start];
        if (opcode != mul) {
            return;
        }
        mOpcode = opcode;
        mOprand1 = codes[start + 1] & 0xff;
        mOprand2 = codes[start + 2] & 0xff;
    }

    @Override
    public void execute() {
        int[] registers = mVm.getRegisters();
        registers[mOprand1] *= registers[mOprand2];
    }

    @Override
    public byte length() {
        return 3;
    }

    @Override
    public String toString() {
        return "mul " +
                "v" + mOprand1 +
                ", v" + mOprand2;
    }
}
